let routes = require("./router-config.js");
const Router = require("koa-router");
const router = new Router();

routes.forEach((item) => {
    // 1. 判断是post还是get router.post/ router.get
    // 2. this
    let cb = item.method.toUpperCase() === "GET" ? router.get : router.post;
    if (Array.isArray(item.callback)) {
        cb.call(router, item.url, ...item.callback);
    } else {
        cb.call(router, item.url, item.callback.bind(router));
    }
});
module.exports = router.routes();